﻿using MyImdb.Models;
using MyImdb.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyImdb.Views
{
    /// <summary>
    /// Interaction logic for SearchView.xaml
    /// </summary>
    public partial class SearchView : UserControl
    {
        private SearchViewModel dataContext;

        public SearchView()
        {
            InitializeComponent();
            dataContext = new SearchViewModel();
            this.DataContext = dataContext;
        }

        private void SearchByKeyboardEnter(object sender, KeyEventArgs e)
        {
            //if (e.Key == Key.Enter)
            //{
            //    dataContext.Search();
            //}
        }

        private void DownloadClick(object sender, RoutedEventArgs e)
        {
            var context = (sender as Button).DataContext;
            dataContext.SelectedImdbItem = context as ImdbItem;

            if (!string.IsNullOrEmpty(dataContext.SelectedImdbItem.Poster))
            {
                var uiElement = ((sender as Button).Parent as Grid).Children[1];
                dataContext.Download(uiElement); 
            }
        }
    }
}
